package com.cly.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cly.domain.SysLog;
import com.cly.mapper.SysLogMapper;
import com.cly.service.SysLogService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.util.StringUtils;

@Service
@Slf4j
public class SysLogServiceImpl extends ServiceImpl<SysLogMapper, SysLog> implements SysLogService{

    @Autowired
    private SysLogMapper sysLogMapper;


    /**
     * 分页查询日志
     *
     * @param page
     * @param sysLog
     * @return
     */
    @Override
    public Page<SysLog> findSysLogPage(Page<SysLog> page, SysLog sysLog) {
        return sysLogMapper.selectPage(page, new LambdaQueryWrapper<SysLog>()
                .like(StringUtils.hasText(sysLog.getUsername()), SysLog::getUsername, sysLog.getUsername())
                .like(StringUtils.hasText(sysLog.getOperation()), SysLog::getOperation, sysLog.getOperation())
                .orderByDesc(SysLog::getCreateDate)
        );
    }
}
